package com.example.warehouse.contrallor;

import com.example.warehouse.entity.ProductType;
import com.example.warehouse.entity.Result;

import com.example.warehouse.service.ProductTypeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/productCategory")
public class contrallorProductCategory {


    @Autowired
    private ProductTypeService productTypeService;

    @RequestMapping("/product-category-tree")
    public Result getTree(){
        List<ProductType> typeTree = productTypeService.findTypeTree();
        return Result.ok(typeTree);
    }

    @RequestMapping("/verify-type-code")
    public Result getTypeCode(String typeCode){
        Result result = productTypeService.queryTypeByCode(typeCode);
        return Result.ok(result);
    }


    @PostMapping("/type-add")
    public Result addtype(@RequestBody ProductType productType){
        productTypeService.addType(productType);
        return Result.ok("添加商品分类成功");
    }

    @DeleteMapping("/type-delete/{ids}")
    public Result delete(@PathVariable Integer ids){
        productTypeService.deleteTypeById(ids);
        return Result.ok("商品分类删除成功");
    }

    @PutMapping("/type-update")
    public Result updateType(@RequestBody ProductType productType){
        productTypeService.updateType(productType);
        return Result.ok("商品分类修改成功");
    }


}
